import { customForm } from '@/components/ProForm/interface/index';
import { ProTableValue } from '@/interface/public';
import dayjs from 'dayjs';

export function useAddForm(proTableBox: ProTableValue) {
  let addForm = reactive<customForm>({
    form: {
      value: ''
    },
    title: '',
    visible: false,
    transitionArr: [],
    labelWidth: [160, 160],
    options: [
      {
        type: 'input',
        label: 'ID',
        prop: 'id',
        hide: true
      },
      {
        type: 'input',
        hide: false,
        prop: 'modelName',
        label: '模板名称',
        rules: [{ required: true, message: '', trigger: 'blur' }]
      },
      {
        type: 'input',
        hide: false,
        prop: 'modelFlag',
        label: '模板标识',
        rules: [{ required: true, message: '', trigger: 'blur' }]
      },
      {
        type: 'date-picker',
        hide: false,
        prop: 'date',
        label: '活动日期',
        rules: [{ required: true, message: '', trigger: 'change' }],
        defaultValue: dayjs().add(1, 'month').format('YYYY-MM-DD'),
        attrs: {
          type: 'date',
          valueFormat: 'YYYY-MM-DD'
        }
      },
      {
        type: 'time-picker',
        hide: false,
        prop: 'time',
        label: '活动时间',
        rules: [{ required: true, message: '', trigger: 'change' }],
        defaultValue: dayjs().format('HH:mm:ss'),
        attrs: {
          type: 'date',
          valueFormat: 'HH:mm:ss'
        }
      },

      {
        type: 'input',
        hide: false,
        prop: 'title1',
        label: '主标题',
        rules: [{ required: true, message: '', trigger: 'blur' }]
      },
      {
        type: 'input',
        hide: false,
        prop: 'title2',
        label: '副标题',
        rules: [{ required: true, message: '', trigger: 'blur' }]
      },
      {
        type: 'input',
        hide: false,
        prop: 'remark',
        label: '备注'
      }
    ],
    saveForm: async form => {
      const params = { ...form };
      params.endTime = params.date + ' ' + params.time;

      await modelSaveModel(params);
      addForm.visible = false;

      elMessage();
      proTableBox.value?.getTableList();
    }
  });

  return { addForm };
}
